#pragma once

#include "boost\noncopyable.hpp"
#include "boost\function.hpp"

class scoped_action :
    boost::noncopyable
{
    typedef boost::function<void()> function_type;
public:
    explicit scoped_action(const function_type& action) : 
    action_(action), released_(false) { }
    void release(){released_ = true;}
    ~scoped_action() 
    { 
        if(!released_)
            action_(); 
    }
private:
    bool released_;
    function_type action_;
};